<template>

</template>
<!-- 下载文件进度 -->
<script>
  function downloadFile(url) {
  var xhr = new XMLHttpRequest();
  xhr.open('GET', url, true);
  xhr.responseType = 'blob';

  xhr.onloadstart = function () {
    console.log('Download started');
  };

  xhr.onprogress = function (event) {
    if (event.lengthComputable) {
      var percentComplete = (event.loaded / event.total) * 100;
      console.log('Download progress: ' + percentComplete + '%');
    }
  };

  xhr.onload = function () {
    if (xhr.status === 200) {
      var blob = xhr.response;
      var fileName = 'file.txt'; // 设置下载文件的名称
      var link = document.createElement('a');
      link.href = window.URL.createObjectURL(blob);
      link.download = fileName;
      link.click();
      console.log('Download completed');
    }
  };

  xhr.onerror = function () {
    console.log('Download failed');
  };

  xhr.send();
}

// 使用示例
downloadFile('http://example.com/file.txt');
</script>
